package com.course.design.controller;

import com.course.design.common.Result;
import com.course.design.entity.Ltxx;
import com.course.design.entity.vo.MessageQueryVO;
import com.course.design.service.LtxxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述:
 *
 * @author qinlianji
 * @create 2020-02-19
 */
@RestController
@Api(tags = "聊天信息")
@RequestMapping("/ltxx")
public class LtxxController {

    @Autowired
    private LtxxService ltxxService;

    @PostMapping("/save")
    @Transactional(rollbackFor = Exception.class)
    public Result save(Ltxx ltxx) {
        ltxxService.save(ltxx);
        return Result.success();
    }

    @GetMapping("/queryHistory/{userId}")
    public Result getHistory(@PathVariable String userId){
        return Result.success(ltxxService.getHistory(userId));
    }

    /**
     * 历史数据查询页面由姓名获得最近的联系人信息
     * @param ygghCd
     * @return
     */
    @ApiOperation(value = "历史数据查询页面由姓名获得最近的联系人信息")
    @GetMapping("/queryUserHistory")
    public Result queryUserHistory(int start, int limit, String ygghCd){
        return Result.success(ltxxService.queryUserHistory(start, limit, ygghCd));
    }

    @PostMapping("/queryMessageHistory")
    public Result queryMessageHistory(@RequestBody MessageQueryVO vo){
        return Result.success(ltxxService.queryMessageHistory(vo.getFromUserId(), vo.getToUserId()));
    }

    @PostMapping("/clearUnread")
    @Transactional(rollbackFor = Exception.class)
    public Result clearUnread(@RequestBody MessageQueryVO vo){
        ltxxService.clearUnread(vo);
        return Result.success();
    }

    @PostMapping("/queryAllMessage")
    public Result queryAllMessage(@RequestBody List<MessageQueryVO> vo){
        return Result.success(ltxxService.queryAllMessage(vo));
    }

}
